package com.fzj.example.thread;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * ClassName: Consumer
 * date: 2019/10/24 15:07
 * Description: TODO
 *
 * @author fanzj@bonree.com
 * @since JDK 1.8
 */
public class Consumer implements Runnable {

    private Queue<Car> queue;

    public Consumer(Queue<Car> queue){
        this.queue=queue;
    }

    @Override
    public void run() {
        while (true){
            try {
                poll();
                System.out.println("还剩余多少台"+queue.size());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void poll() throws InterruptedException {
        synchronized (queue){
            if(queue.size()<=100){
                System.out.println("通知生产");
                queue.notify();
            }else{
                queue.poll();
            }
        }

    }
}
